#!/usr/local/bin/python

import fileinput, glob, string, sys, os, shutil, re
from os.path import join

tags = [
'End',    #00
'ShowFrame',    #01
'DefineShape',    #02
'FreeCharacter',    #03 not in spec
'PlaceObject',    #04
'RemoveObject',    #05
'DefineBits',    #06
'DefineButton',    #07
'JPEGTables',    #08
'SetBackgroundColor',    #09
'DefineFont',    #10
'DefineText',    #11
'DoAction',    #12
'DefineFontInfo',    #13
'DefineSound',    #14
'StartSound',    #15
'StopSound',    #16 not in spec
'DefineButtonSound',    #17
'SoundStreamHead',    #18
'SoundStreamBlock',    #19
'DefineBitsLossless',    #20
'DefineBitsJPEG2',    #21
'DefineShape2',    #22
'DefineButtonCxform',    #23
'Protect',    #24
'PathsArePostScript',    #25 not in spec
'PlaceObject2',    #26
'0',

'RemoveObject2',    #28
'SyncFrame',    #29 not in spec
'0',

'FreeAll',    #31 not in spec
'DefineShape3',    #32
'DefineText2',    #33
'DefineButton2',    #34
'DefineBitsJPEG3',    #35
'DefineBitsLossless2',    #36
'DefineEditText',    #37
'DefineVideo',    #38 not in spec
'DefineSprite',    #39
'NameCharacter',    #40 not in spec
'ProductInfo',    #41 not in spec
'DefineTextFormat',    #42 not in spec
'FrameLabel',    #43
'DefineBehavior',    #44 not in spec
'SoundStreamHead2',    #45
'DefineMorphShape',    #46
'FrameTag',    #47 not in spec
'DefineFont2',    #48
'GenCommand',    #49 not in spec
'DefineCommandObj',    #50 not in spec
'CharacterSet',    #51 not in spec
'FontRef',    #52 not in spec
'DefineFunction',    #53 not in spec
'PlaceFunction',    #54 not in spec
'GenTagObject',    #55 not in spec
'ExportAssets',    #56
'ImportAssets',    #57
'EnableDebugger',    #58
'DoInitAction',    #59
'DefineVideoStream',    #60
'VideoFrame',    #61
'DefineFontInfo2',    #62
'DebugID',    #63 not in spec
'EnableDebugger2',    #64
'ScriptLimits',    #65
'SetTabIndex',    #66
'0',    #67 not in spec
'0',    #68 not in spec
'FileAttributes',    #69
'PlaceObject3',    #70
'ImportAssets2',    #71
'DoABC',    #72 not in spec
'DefineFontAlignZones',    #73
'CSMTextSettings',    #74
'DefineFont3',    #75
'SymbolClass',    #76
'Metadata',    #77
'DefineScalingGrid',    #78
'0',
'0',
'0',
'DoABC2',    #82
'DefineShape4',    #83
'DefineMorphShape2',    #84
'0',
'DefineSceneAndFrameLabelData',    #86
'DefineBinaryData',    #87
'DefineFontName',    #88
'StartSound2',    #89
'DefineBitsJPEG4',    #90
'DefineFont4'    #91
	]


def PascalToConst(s, code, prefix):
	x = prefix;
	last_char_upper = True;
	for c in s:
		if c.isdigit() or (c.isupper() and not last_char_upper):
			x += '_'
		last_char_upper = c.isupper()
		x += c.upper()
	x += ':uint = ' + hex(code) + ';'
	x += '\t\t//' + str(code)
	return x 
	
	
def makeFiles(tag, type):
	templ = 'Template' + type + '.as'
	spath = os.path.join(cwd, templ)
	fname = tag
	if type != 'Object':
		fname += type
	fname += '.as'
	dpath = os.path.join(cwd, type.lower() +'/' + fname  )
	#shutil.copy(spath, dpath)
	input = open(spath)
	output = open(dpath, 'w');
	for s in input:
		s = s.replace('/*NAME//*/', tag)
		output.write( s )
	
	input.close()
	output.close()
	
ix = -1
cwd = os.getcwd();
for tag in tags:
	ix += 1
	if tag != '0':
		#print PascalToConst(tag, ix, 'public static const ')
		#makeFiles(tag, 'Object')
		#makeFiles(tag, 'Codec')
		#makeFiles(tag, 'Encoding')
		makeFiles(tag, 'Exporter')
		
	
	
